//
//  UserInfoVC.m
//  jzyParents
//
//  Created by 任辰东 on 2022/5/1.
//

#import "UserInfoVC.h"
#import "RCDTextFeidView.h"

@interface UserInfoVC ()
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIImageView *avatarImageView;
@property (nonatomic, strong) UILabel *avatarLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIControl *avatarControl;

@property (nonatomic, strong) RCDTextFeidView *IDView;
@property (nonatomic, strong) RCDTextFeidView *nameView;
@property (nonatomic, strong) RCDTextFeidView *genderView;
@property (nonatomic, strong) RCDTextFeidView *mobileView;
@end

@implementation UserInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"个人资料";
    
    [self configInfo];
}

-(void)configInfo
{

    self.avatarImageView.hidden = YES;
    self.avatarLabel.hidden = NO;
    
    NSString *username = [GVUserDefaults standardUserDefaults].student_name;
    
    if (username.length > 2) {
        NSString *name = [username substringWithRange:NSMakeRange(username.length-2, 2)];
        self.avatarLabel.text = name;
    }else{
        self.avatarLabel.text = username;
    }
    
    self.nameLabel.text = [NSString stringWithFormat:@"%@",[GVUserDefaults standardUserDefaults].student_name];;
    
    self.IDView.model.content = [NSString stringWithFormat:@"ID%@",[GVUserDefaults standardUserDefaults].student_id];
    self.nameView.model.content = self.nameLabel.text;
    self.genderView.model.content = [GVUserDefaults standardUserDefaults].gender.integerValue == 1 ? @"男":@"女";
    self.mobileView.model.content = [GVUserDefaults standardUserDefaults].id_card;
}

-(NSString *)setupInfo:(NSString *)info
{
    return IsEmpty(info) ? @"无":info;
}

-(void)setupViews
{
    [self.bgScrollView.contentView addSubview:self.topView];
    [self.topView addSubview:self.avatarLabel];
    [self.topView addSubview:self.avatarImageView];
    [self.topView addSubview:self.nameLabel];
    [self.topView addSubview:self.avatarControl];
    
    [self.bgScrollView.contentView addSubview:self.IDView];
    [self.bgScrollView.contentView addSubview:self.nameView];
    [self.bgScrollView.contentView addSubview:self.genderView];
    [self.bgScrollView.contentView addSubview:self.mobileView];
}

-(void)setupLayout
{
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.right.equalTo(self.bgScrollView.contentView);
    }];
    
    [self.avatarLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.topView).offset(20);
        make.centerX.equalTo(self.topView);
        make.height.width.mas_equalTo(50);
    }];
    self.avatarLabel.layer.cornerRadius = 5;
    self.avatarLabel.layer.masksToBounds = YES;
    
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.topView).offset(20);
        make.centerX.equalTo(self.topView);
        make.height.width.mas_equalTo(50);
    }];
    self.avatarImageView.layer.cornerRadius = 5;
    self.avatarImageView.layer.masksToBounds = YES;
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.avatarImageView.mas_bottom).offset(10);
        make.left.equalTo(self.topView).offset(15);
        make.right.equalTo(self.topView).offset(-15);
        make.bottom.equalTo(self.topView).offset(-20);
    }];
    
    [self.avatarControl mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.topView).offset(20);
        make.centerX.equalTo(self.topView);
        make.height.width.mas_equalTo(50);
    }];
    self.avatarControl.layer.cornerRadius = 5;
    self.avatarControl.layer.masksToBounds = YES;
    
    [self.IDView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.topView.mas_bottom).offset(10);
        make.left.equalTo(self.bgScrollView.contentView).offset(-6);
        make.right.equalTo(self.bgScrollView.contentView);
        make.height.mas_equalTo(55);
    }];
    
    [self.nameView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.IDView.mas_bottom).offset(0);
        make.left.equalTo(self.bgScrollView.contentView).offset(-6);
        make.right.equalTo(self.bgScrollView.contentView);
        make.height.mas_equalTo(55);
    }];
    
    [self.genderView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.nameView.mas_bottom).offset(0);
        make.left.equalTo(self.bgScrollView.contentView).offset(-6);
        make.right.equalTo(self.bgScrollView.contentView);
        make.height.mas_equalTo(55);
    }];
    
    [self.mobileView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.genderView.mas_bottom).offset(0);
        make.left.equalTo(self.bgScrollView.contentView).offset(-6);
        make.right.equalTo(self.bgScrollView.contentView);
        make.height.mas_equalTo(55);
        make.bottom.equalTo(self.bgScrollView.contentView);
    }];
}

#pragma mark -- lazyload

-(UIView *)topView
{
    if (!_topView) {
        _topView = [UIView new];
        _topView.backgroundColor = UIColorFromHex(kColorWhite);
        [_topView addBottomLine];
    }
    return _topView;
}

-(UIImageView *)avatarImageView
{
    if (!_avatarImageView) {
        _avatarImageView = [UIImageView new];
        _avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
        _avatarImageView.clipsToBounds = YES;
    }
    return _avatarImageView;
}

-(UILabel *)avatarLabel
{
    if (!_avatarLabel) {
        _avatarLabel = [UILabel new];
        _avatarLabel.backgroundColor = UIColorFromHex(kColorMain);
        _avatarLabel.textColor = UIColorFromHex(kColorWhite);
        _avatarLabel.font = UIFontSize(15);
        _avatarLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _avatarLabel;
}

-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.textColor = UIColorFromHex(0x00000);
        _nameLabel.font = UIFontSize(15);
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLabel;
}

-(UIControl *)avatarControl
{
    if (!_avatarControl) {
        _avatarControl = [UIControl new];
        _avatarControl.backgroundColor = UIColor.clearColor;
    }
    return _avatarControl;
}

-(RCDTextFeidView *)IDView
{
    if (!_IDView) {
        
        RCDTextFeidViewModel *model = [RCDTextFeidViewModel new];
        model.leftTitle = @"用户ID";
        model.leftTitleColor = UIColorFromHex(kColorSubTitle);
        model.leftTitleFont = UIFontSize(16);
        model.contentFont = UIFontSize(16);
        model.contentColor = UIColorFromHex(0x00000);
        model.alignment = NSTextAlignmentRight;
        model.isNotEnable = YES;
        _IDView = [[RCDTextFeidView alloc]initWithModel:model];
        _IDView.backgroundColor = UIColorFromHex(kColorWhite);
        [_IDView addTopLine];
        [_IDView addBottomLineWithEdge:UIEdgeInsetsMake(0, 21, 0, 15)];
        
    }
    return _IDView;
}

-(RCDTextFeidView *)nameView
{
    if (!_nameView) {
        
        RCDTextFeidViewModel *model = [RCDTextFeidViewModel new];
        model.leftTitle = @"姓名";
        model.leftTitleColor = UIColorFromHex(kColorSubTitle);
        model.leftTitleFont = UIFontSize(16);
        model.contentFont = UIFontSize(16);
        model.contentColor = UIColorFromHex(0x00000);
        model.alignment = NSTextAlignmentRight;
        model.isNotEnable = YES;
        _nameView = [[RCDTextFeidView alloc]initWithModel:model];
        _nameView.backgroundColor = UIColorFromHex(kColorWhite);
        [_nameView addBottomLineWithEdge:UIEdgeInsetsMake(0, 21, 0, 15)];
        
    }
    return _nameView;
}

-(RCDTextFeidView *)genderView
{
    if (!_genderView) {
        
        RCDTextFeidViewModel *model = [RCDTextFeidViewModel new];
        model.leftTitle = @"性别";
        model.leftTitleColor = UIColorFromHex(kColorSubTitle);
        model.leftTitleFont = UIFontSize(16);
        model.contentFont = UIFontSize(16);
        model.contentColor = UIColorFromHex(0x00000);
        model.alignment = NSTextAlignmentRight;
        model.isNotEnable = YES;
        _genderView = [[RCDTextFeidView alloc]initWithModel:model];
        _genderView.backgroundColor = UIColorFromHex(kColorWhite);
        [_genderView addBottomLineWithEdge:UIEdgeInsetsMake(0, 21, 0, 15)];
        
    }
    return _genderView;
}

-(RCDTextFeidView *)mobileView
{
    if (!_mobileView) {
        
        RCDTextFeidViewModel *model = [RCDTextFeidViewModel new];
        model.leftTitle = @"身份证号";
        model.leftTitleColor = UIColorFromHex(kColorSubTitle);
        model.leftTitleFont = UIFontSize(16);
        model.contentFont = UIFontSize(16);
        model.contentColor = UIColorFromHex(0x00000);
        model.alignment = NSTextAlignmentRight;
//        model.rightImgPath = @"arrow";
        model.isNotEnable = YES;
        _mobileView = [[RCDTextFeidView alloc]initWithModel:model];
        _mobileView.backgroundColor = UIColorFromHex(kColorWhite);
        [_mobileView addBottomLine];
        
    }
    return _mobileView;
}

@end
